package Controller;

import Handler.*;
import com.sun.org.apache.xpath.internal.operations.Or;
import org.omg.CORBA.ORB;
import pojo.Product;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(value = "*.do")
public class ControllerServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String path=request.getServletPath();
        path=path.substring(0,path.lastIndexOf("."));
        System.out.println(path);
        if(path.equals("/user/login"))
        {
            UserHandler userHandler=new UserHandler();
            userHandler.login(request, response);
        }
        else if(path.equals("/user/showRegister"))
        {
            UserHandler userHandler = new UserHandler();
            userHandler.showregister(request, response);
        }
        else if(path.equals("/user/register"))
        {
            UserHandler userHandler=new UserHandler();
            userHandler.register(request, response);
        }
        else if(path.equals("/user/loginOut"))
        {
            UserHandler userHandler=new UserHandler();
            userHandler.logout(request, response);
        }
        else if("/user/toModify".equals(path)){
            UserHandler userHandler = new UserHandler();
            userHandler.toModify(request,response);
        }else if("/user/modify".equals(path)){
            UserHandler userHandler = new UserHandler();
            userHandler.modify(request,response);
        }
        else if("/user/deleteUserById".equals(path)){
            UserHandler userHandler=new UserHandler();
            userHandler.deleteUser(request,response);
        }

        else if(path.equals("/product/showAll"))
        {
            ProductHandler productHandler=new ProductHandler();
            productHandler.showProductAll(request, response);
        }
        else if(path.equals("/product/addCart"))
        {
            ShopCartHandler shopCartHandler=new ShopCartHandler();
            shopCartHandler.addToCart(request, response);
        }
        else if(path.equals("/product/showprodetails"))
        {
            ProductHandler productHandler=new ProductHandler();
            productHandler.showprodetails(request, response);
        }
        else if(path.equals("/cart/showCart"))
        {
            ShopCartHandler shopCartHandler=new ShopCartHandler();
            shopCartHandler.showCartByUser(request, response);
        }
        else if(path.equals("/cart/changeProductNumber"))
        {
            ShopCartHandler shopCartHandler=new ShopCartHandler();
            shopCartHandler.changeProductNumber(request, response);
        }
        else if(path.equals("/cart/deleteCartProduct"))
        {
            ShopCartHandler shopCartHandler=new ShopCartHandler();
            shopCartHandler.deleteProductFromShopCart(request, response);
        }
        else if(path.equals("/order/confOrder"))
        {
            OrderHandler orderHandler=new OrderHandler();
            orderHandler.confOrder(request, response);
        }
        else if("/admin/supplierList".equals(path)){
            SuperUserHandler superUserHandler=new SuperUserHandler();
            superUserHandler.showSupplier(request,response);
        }
        else if("/admin/productList".equals(path)){
            SuperUserHandler superUserHandler=new SuperUserHandler();
            superUserHandler.showProduct(request,response);
        }
        else if("/supplier/showProduct".equals(path)){
            SuperUserHandler superUserHandler=new SuperUserHandler();
            superUserHandler.showSupplierProduct(request,response);
        }
        else if("/supplier/deleteSupplierById".equals(path)){
            SuperUserHandler superUserHandler=new SuperUserHandler();
            superUserHandler.deleteSupplier(request,response);
        }
        else if("/admin/index".equals(path)){
            SuperUserHandler superUserHandler=new SuperUserHandler();
            superUserHandler.showUser(request,response);
        }
        else if("/admin/addSupplier".equals(path)){
            SuperUserHandler superUserHandler=new SuperUserHandler();
            superUserHandler.addSupplier(request,response);
        }
        else if("/supplier/addSupplier".equals(path)){
            SuperUserHandler superUserHandler=new SuperUserHandler();
            superUserHandler.addSuppliers(request,response);
        }
        else if("/admin/order".equals(path)){
            SuperUserHandler superUserHandler=new SuperUserHandler();
            superUserHandler.showOrder(request,response);
        }
        else if("/Order/showItems".equals(path)){
            SuperUserHandler superUserHandler=new SuperUserHandler();
            superUserHandler.showItems(request,response);
        }
        else if("/Order/updateStatus".equals(path)){
            SuperUserHandler superUserHandler=new SuperUserHandler();
            superUserHandler.updateStatus(request,response);
        }
        else if("/order/updateOrder".equals(path)){
            SuperUserHandler superUserHandler=new SuperUserHandler();
            superUserHandler.updateOrder(request,response);
        }
    }
}
